import { LeaderAttributeType } from "../LeaderEnum";
import { LeaderNumeric } from "./LeaderNumeric";

/** 所有模块主角属性集合 */
export class LeaderNumericMap {
    /** 主角属性 */
    private attributes: Map<LeaderAttributeType, LeaderNumeric> = new Map();

    /** MVVM组件数据 */
    private vm: any = {};

    constructor(vm: any) {
        this.vm = vm;
    }

    /** 获取主角属性 */
    get(type: LeaderAttributeType): LeaderNumeric {
        var attr = this.attributes.get(type);
        if (attr == null) {
            attr = new LeaderNumeric(type, this);
            this.attributes.set(type, attr);

            attr.onUpdate = (rn: LeaderNumeric) => {
                this.vm[rn.type] = rn.value;
            };
        }
        return attr;
    }

    /** 重置属性值为零 */
    reset() {

        // 清理属性值
        this.attributes.forEach((value: LeaderNumeric, key: LeaderAttributeType, map: Map<LeaderAttributeType, LeaderNumeric>) => {
            value.reset();
        });
    }
}